<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>TG管理员登录界面</title>
    <link rel="stylesheet" type="text/css" href="../static/css/login.css">
</head>

<body>
    <div id="wrapper" class="login-page">
        <div id="login_form" class="form">
            <form class="register-form">
                <input type="text" placeholder="用户名" value="admin" id="r_user_name" />
                <input type="password" placeholder="密码" id="r_password" />
                <input type="text" placeholder="电子邮件" id="r_emial" />
                <p class="message"> <a href="#">立刻登录</a></p>
            </form>
            <form class="login-form">
                <h2>管理登录</h2>
                <input type="text" placeholder="用户名" value="admin" id="user_name" />
                <input type="password" placeholder="密码" id="password" />
                <button id="login">登　录</button>
            </form>
        </div>
    </div>

    <script src="http://www.jq22.com/jquery/jquery-1.10.2.js"></script>
    <script type="text/javascript">
        
        function check_login() {
            var username = $("#user_name").val();
            var password = $("#password").val();
            var inputData = {'username':username, 'password':password}
            $.ajax({
                type: 'POST',
                url:  'http://127.0.0.1:8000/v1/TGadmin/login',
                contentType: 'application/json',
                data: JSON.stringify(inputData),
                success: function (result) {
                    if (result.code == 200) { //登录成功
                        window.localStorage.clear()
                        window.localStorage.setItem('TGshop_token', result.data.token);
                        window.localStorage.setItem('TGshop_admin', result.username);
                        alert('登录成功');
                        window.location.href = '/index';
                    } else { //登录失败
                        $("#login_form").removeClass('shake_effect');
                        setTimeout(function () {
                            $("#login_form").addClass('shake_effect')
                        }, 1);
                        $('#showResult').html(result.error);
                    }
                }
            });
        }
        $("#login").click(function () {
            check_login();
            return false;
        })

    </script>
</body>

</html>